require(['jquery', 'cookie', 'app', "lay"], function ($) {
    require(['vue'], function (Vue) {
        var dic = new Vue({
            el: ".vue-box"
            , data: {
                where: {},
                userInfo: {},
                money: "",
                thatUser: "",
            }
            , created: function () {
                this.userInfo = JSON.parse(localStorage.getItem("userInfo"));
                this.loadPage();
            }
            , methods: {
                loadPage: function () {
                    load();
                    var toolbar = [];
                    var tool = [];
                    toolbar.push({
                        "clas": "",
                        "eve": "ADD",
                        "tit": "新增",
                        "fnc": function (data) {
                            openAdd("新增商品", "/view/shop/add");
                        }
                    });
                    toolbar.push({
                        "clas": "layui-btn-danger",
                        "eve": "XG",
                        "tit": "修改",
                        "fnc": function (data) {
                            if (data.length <= 0) {
                                alr("请选择一条记录");
                                return;
                            } else {
                                openAdd("修改商品", "/view/shop/add?id=" + data[0].id);
                            }
                        }
                    });
                    toolbar.push({
                        "clas": "layui-btn-danger",
                        "eve": "DEL",
                        "tit": "上架/下架",
                        "fnc": function (data) {
                            if (data.length <= 0) {
                                alr("请选择一条记录");
                                return;
                            }
                            data[0]['status'] = !data[0]['status'];
                            var re = playPost("v1/api/shop/save", "", JSON.stringify(data[0]));
                            alr(re.msg);
                            setTimeout(function () {
                                window.reload();
                            }, 500);
                            return false;
                        }
                    });
                    bspVIEW($("#authoritiesTable"), "/v1/api/shop/all", [
                        {type: 'radio',width: 150},
                        {type: 'numbers'},
                        {field: 'id', title: '商品id', minWidth: 50, width: 120},
                        {field: 'name', title: '商品名称', minWidth: 50, width: 120},
                        {field: 'spack', title: '商品说明', minWidth: 50, width: 120},
                        {field: 'money', title: '商品价格', minWidth: 50, width: 120},
                        {
                            templet: function (d) {
                                if (d.status) {
                                    return "<p style=\"background-color: green;color: white\">上架中 </p>";
                                } else {
                                    return "<p style=\"background-color: red;color: white\">下架</p>";
                                }
                            },
                            align: 'center',
                            width: 120,
                            title: '商品状态'
                            , minWidth: 120
                        }
                    ], {common: this.where}, toolbar, tool, function (res, curr, count) {

                    });
                },
                seachs: function () {
                    this.where = fromName($(".el-form"));
                    this.loadPage();
                },
                refer: function () {

                }
            }
        });
    })
});